package com.sunday.volunteer.admin.adapter.index;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.squareup.picasso.Picasso;
import com.sunday.common.utils.DeviceUtils;
import com.sunday.common.widgets.CircleImageView;
import com.sunday.volunteer.admin.R;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/11/1.
 * 导游活动报名人数
 */
public class Tab1EntryAdapter extends RecyclerView.Adapter {

    private Context context;
    private int width;
    private List<String> members;

    public Tab1EntryAdapter(Context context , List<String> members) {
        this.context = context;
        width = DeviceUtils.getDisplay(context).widthPixels/6;
        this.members = members;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.tab1_entry_item, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        ViewHolder holder1 = (ViewHolder) holder;
        Picasso.with(context)
                .load(members.get(position))
                .resize(width,width)
                .placeholder(R.mipmap.person_default)
                .error(R.mipmap.person_default)
                .into(holder1.imgHeader);
        holder1.lMain.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (itemClickListener!=null){

                }
            }
        });
    }

    public interface ItemClickListener{
        void itemClick(View v, int position);
    }
    private ItemClickListener itemClickListener;
    public void setItemClickListener(ItemClickListener itemClickListener){
        this.itemClickListener = itemClickListener;
    }

    @Override
    public int getItemCount() {
        return members.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.img_header)
        CircleImageView imgHeader;
        @Bind(R.id.l_main)
        LinearLayout lMain;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
